package com.itheima.a02udpdemo1;

import java.io.IOException;
import java.net.*;

public class SendMessageDemo1 {
    public static void main(String[] args) throws IOException {
        //Udp协议发送消息

        //找快递公司 也就是创建DatagramSocket对象
        DatagramSocket ds = new DatagramSocket(54000);

        //打包信件 也就是创建DatagramPacket对象
        String str = "hello world";
        byte[] bytes = str.getBytes();
        InetAddress address = InetAddress.getByName("127.0.0.1");
        int port = 10086;

        DatagramPacket dp = new DatagramPacket(bytes, bytes.length, address, port);

        //发送信件 也就是调用DategramSocket对象的send方法
        ds.send(dp);

        //关闭快递公司 也就是调用DategramSocket对象的close方法
        ds.close();
    }
}
